\documentclass[11pt,hyperref,]{ctexart}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
\else % if luatex or xelatex
  \ifxetex
    \usepackage{xltxtra,xunicode}
  \else
    \usepackage{fontspec}
  \fi
  \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
  \newcommand{\euro}{€}
\fi
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\usepackage[left = 1cm, right = 1cm, top = 2.0cm, bottom = 2.0cm]{geometry}
\ifxetex
  \usepackage[setpagesize=false, % page size defined by xetex
              unicode=false, % unicode breaks when used with xetex
              xetex]{hyperref}
\else
  \usepackage[unicode=true]{hyperref}
\fi
\usepackage[usenames,dvipsnames]{color}
\hypersetup{breaklinks=true,
            bookmarks=true,
            pdfauthor={Heaven},
            pdftitle={业绩计算},
            colorlinks=true,
            citecolor=blue,
            urlcolor=blue,
            linkcolor=magenta,
            pdfborder={0 0 0}}
\urlstyle{same}  % don't use monospace font for urls
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\RecustomVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\},formatcom=\xeCJKVerbAddon}
\usepackage{longtable,booktabs}
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{5}

\title{业绩计算}
\author{Heaven}
\date{2018年02月06日}

% Redefines (sub)paragraphs to behave more like sections
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi

\begin{document}
\maketitle

{
\setcounter{tocdepth}{2}
\tableofcontents
}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{df <-}\StringTok{ }\NormalTok{readxl}\OperatorTok{::}\KeywordTok{read_excel}\NormalTok{(}\StringTok{"./data/tp391.13-635-人事办公管理/36.业绩统计年度报表.xlsx"}\NormalTok{, }\DataTypeTok{sheet =} \StringTok{"销售明细表"}\NormalTok{)}

\NormalTok{df}\OperatorTok{$}\NormalTok{销售月份 <-}\StringTok{ }\KeywordTok{gsub}\NormalTok{(}\StringTok{"102(/[0-9]\{2\})"}\NormalTok{, }\StringTok{"2017}\CharTok{\textbackslash{}\textbackslash{}}\StringTok{1/01"}\NormalTok{, df}\OperatorTok{$}\NormalTok{销售月份, }\DataTypeTok{perl =} \OtherTok{TRUE}\NormalTok{) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{as.Date}\NormalTok{()}

\NormalTok{df <-}\StringTok{ }\NormalTok{df }\OperatorTok{%>%}\StringTok{ }\KeywordTok{mutate}\NormalTok{(月份 =}\StringTok{ }\KeywordTok{months}\NormalTok{(销售月份))}
\end{Highlighting}
\end{Shaded}

\subsection{业绩月报表}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{thismonth <-}\StringTok{ "一月"}
\NormalTok{df.month <-}\StringTok{ }\NormalTok{df }\OperatorTok{%>%}\StringTok{ }\NormalTok{dplyr}\OperatorTok{::}\KeywordTok{filter}\NormalTok{(月份 }\OperatorTok{==}\StringTok{ "一月"}\NormalTok{) }\OperatorTok{%>%}\StringTok{ }
\StringTok{  }\KeywordTok{group_by}\NormalTok{(员工编号, 姓名, 商品种类) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{summarise}\NormalTok{(销售金额 =}\StringTok{ }\KeywordTok{sum}\NormalTok{(销售金额)) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{ungroup}\NormalTok{() }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{spread}\NormalTok{(}\DataTypeTok{key =} \StringTok{"商品种类"}\NormalTok{, }\DataTypeTok{value =} \StringTok{"销售金额"}\NormalTok{) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{mutate}\NormalTok{(销售金额 =}\StringTok{ }\KeywordTok{rowSums}\NormalTok{(}\KeywordTok{select}\NormalTok{(., }\KeywordTok{c}\NormalTok{(}\DecValTok{3}\OperatorTok{:}\DecValTok{6}\NormalTok{)))) }

\CommentTok{# 输出月报表表格}
\KeywordTok{library}\NormalTok{(kableExtra)}
\NormalTok{df.month }\OperatorTok{%>%}\StringTok{ }\NormalTok{knitr}\OperatorTok{::}\KeywordTok{kable}\NormalTok{() }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{kable_styling}\NormalTok{(}\DataTypeTok{latex_options =} \StringTok{"scale_down"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{longtable}[]{@{}llccccc@{}}
\toprule
员工编号 & 姓名 & 财产险 & 旅游平安险 & 汽车强制险 & 意外险 &
销售金额\tabularnewline
\midrule
\endhead
JY0001 & 张芳城 & 120000 & 50000 & 10000 & 212000 &
392000\tabularnewline
JY0002 & 郭秋阳 & 210000 & 50500 & 10300 & 210500 &
481300\tabularnewline
JY0003 & 林文华 & 80000 & 51000 & 10600 & 80000 & 221600\tabularnewline
JY0004 & 蔡玉云 & 300000 & 30000 & 10900 & 150000 &
490900\tabularnewline
JY0005 & 陈静雯 & 120000 & 52000 & 12000 & 300000 &
484000\tabularnewline
JY0006 & 林健华 & 70000 & 52500 & 11500 & 215000 & 349000\tabularnewline
JY0007 & 刘名昌 & 170000 & 25000 & 8000 & 20000 & 223000\tabularnewline
JY0008 & 吴丽贞 & 180000 & 53500 & 11100 & 221000 &
465600\tabularnewline
JY0009 & 林雅琳 & 200000 & 54000 & 10900 & 120000 &
384900\tabularnewline
JY0010 & 王光辉 & 500000 & 55000 & 12000 & 227000 &
794000\tabularnewline
\bottomrule
\end{longtable}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#输出月报表图表}
\NormalTok{df.month }\OperatorTok{%>%}\StringTok{ }\KeywordTok{ggplot}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\KeywordTok{reorder}\NormalTok{(姓名, 销售金额), 销售金额)) }\OperatorTok{+}
\StringTok{  }\KeywordTok{geom_bar}\NormalTok{(}\DataTypeTok{stat =} \StringTok{"identity"}\NormalTok{) }\OperatorTok{+}\StringTok{ }
\StringTok{  }\KeywordTok{ggtitle}\NormalTok{(}\KeywordTok{paste0}\NormalTok{(}\StringTok{"员工销售金额月报表 - "}\NormalTok{, thismonth)) }\OperatorTok{+}
\StringTok{  }\KeywordTok{xlab}\NormalTok{(}\StringTok{"姓名"}\NormalTok{) }\OperatorTok{+}\StringTok{ }\KeywordTok{ylab}\NormalTok{(}\StringTok{"销售金额"}\NormalTok{) }\OperatorTok{+}
\StringTok{  }\KeywordTok{geom_text}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\DataTypeTok{label =}\NormalTok{ 销售金额), }\DataTypeTok{color =} \StringTok{"white"}\NormalTok{, }\DataTypeTok{hjust =} \FloatTok{1.5}\NormalTok{) }\OperatorTok{+}
\StringTok{  }\KeywordTok{coord_flip}\NormalTok{()}
\end{Highlighting}
\end{Shaded}

\includegraphics{tp391.13-635-chapter7_files/figure-latex/yeji-1.pdf}

\subsection{业绩奖金计算表}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{jiangjin.guize <-}\StringTok{ }\NormalTok{readxl}\OperatorTok{::}\KeywordTok{read_excel}\NormalTok{(}\StringTok{"./data/tp391.13-635-人事办公管理/chapter7.xlsx"}\NormalTok{, }\StringTok{"参数表"}\NormalTok{, }\DataTypeTok{range =} \StringTok{"D2:F7"}\NormalTok{)}
\NormalTok{yeji.guize <-}\StringTok{ }\NormalTok{readxl}\OperatorTok{::}\KeywordTok{read_excel}\NormalTok{(}\StringTok{"./data/tp391.13-635-人事办公管理/chapter7.xlsx"}\NormalTok{, }\StringTok{"参数表"}\NormalTok{, }\DataTypeTok{range =} \StringTok{"A2:B6"}\NormalTok{)}

\NormalTok{transmute_guize_onecol <-}\StringTok{ }\ControlFlowTok{function}\NormalTok{(df_, columnName_, df.guize_, }\DataTypeTok{df.guize.type_ =} \DecValTok{1}\NormalTok{, }\DataTypeTok{df.guize.valueCol_ =} \DecValTok{2}\NormalTok{) \{}
\NormalTok{  rst <-}\StringTok{ }\KeywordTok{transmute}\NormalTok{(df_, }\DataTypeTok{V1 =} \KeywordTok{get}\NormalTok{(columnName_) }\OperatorTok{*}\StringTok{ }
\StringTok{              }\NormalTok{yeji.guize[}\KeywordTok{which}\NormalTok{(df.guize_[,df.guize.type_] }\OperatorTok{==}\StringTok{ }\NormalTok{columnName_),df.guize.valueCol_] }\OperatorTok{%>%}
\StringTok{              }\KeywordTok{as.numeric}\NormalTok{())}
  \CommentTok{#names(rst)[1] <- paste0(columnName_, ".guize")}
\NormalTok{  rst <-}\StringTok{ }\KeywordTok{as.data.frame}\NormalTok{(rst) }\OperatorTok{%>%}\StringTok{ }\NormalTok{.[, }\StringTok{"V1"}\NormalTok{]  }
  \KeywordTok{return}\NormalTok{(rst)}
\NormalTok{\}}

\NormalTok{df.month <-}\StringTok{ }\NormalTok{df.month }\OperatorTok{%>%}\StringTok{ }\KeywordTok{mutate}\NormalTok{(业绩金额 =}\StringTok{ }\KeywordTok{transmute_guize_onecol}\NormalTok{(., }\StringTok{"财产险"}\NormalTok{, yeji.guize) }\OperatorTok{+}
\StringTok{                          }\KeywordTok{transmute_guize_onecol}\NormalTok{(., }\StringTok{"旅游平安险"}\NormalTok{, yeji.guize) }\OperatorTok{+}
\StringTok{                          }\KeywordTok{transmute_guize_onecol}\NormalTok{(., }\StringTok{"汽车强制险"}\NormalTok{, yeji.guize) }\OperatorTok{+}
\StringTok{                          }\KeywordTok{transmute_guize_onecol}\NormalTok{(., }\StringTok{"意外险"}\NormalTok{, yeji.guize))}

\CommentTok{#}
\NormalTok{df.month}\OperatorTok{$}\NormalTok{奖金系数 <-}\StringTok{ }\KeywordTok{cut}\NormalTok{(df.month}\OperatorTok{$}\NormalTok{业绩金额, }\DataTypeTok{breaks =} \KeywordTok{c}\NormalTok{(jiangjin.guize}\OperatorTok{$}\NormalTok{范围, }\OtherTok{Inf}\NormalTok{), }\DataTypeTok{labels =}\NormalTok{ jiangjin.guize}\OperatorTok{$}\NormalTok{数值) }\OperatorTok{%>%}\StringTok{ }
\StringTok{  }\KeywordTok{as.character}\NormalTok{() }\OperatorTok{%>%}\StringTok{ }
\StringTok{  }\KeywordTok{as.numeric}\NormalTok{()}

\NormalTok{df.month <-}\StringTok{ }\NormalTok{df.month }\OperatorTok{%>%}\StringTok{ }\KeywordTok{mutate}\NormalTok{(业绩奖金 =}\StringTok{ }\KeywordTok{round}\NormalTok{(业绩金额 }\OperatorTok{*}\StringTok{ }\NormalTok{奖金系数))}
\NormalTok{df.month.sum <-}\StringTok{ }\KeywordTok{colSums}\NormalTok{(df.month[}\DecValTok{3}\OperatorTok{:}\DecValTok{10}\NormalTok{])}
\NormalTok{df.month.sum <-}\StringTok{ }\NormalTok{df.month.sum }\OperatorTok{%>%}\StringTok{  }\KeywordTok{t}\NormalTok{() }\OperatorTok{%>%}\StringTok{ }\KeywordTok{as.data.frame}\NormalTok{()}
\NormalTok{df.month.sum[,}\StringTok{"姓名"}\NormalTok{] <-}\StringTok{ "合计"}
\NormalTok{df.month <-}\StringTok{ }\NormalTok{df.month }\OperatorTok{%>%}\StringTok{ }\KeywordTok{bind_rows}\NormalTok{(df.month.sum)}

\NormalTok{df.month }\OperatorTok{%>%}\StringTok{ }\KeywordTok{select}\NormalTok{(}\OperatorTok{-}\NormalTok{奖金系数) }\OperatorTok{%>%}\StringTok{ }\NormalTok{knitr}\OperatorTok{::}\KeywordTok{kable}\NormalTok{() }\OperatorTok{%>%}\StringTok{ }
\StringTok{  }\NormalTok{kableExtra}\OperatorTok{::}\KeywordTok{kable_styling}\NormalTok{(}\DataTypeTok{font_size =} \DecValTok{6}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{longtable}[]{@{}llccccccc@{}}
\toprule
员工编号 & 姓名 & 财产险 & 旅游平安险 & 汽车强制险 & 意外险 & 销售金额 &
业绩金额 & 业绩奖金\tabularnewline
\midrule
\endhead
JY0001 & 张芳城 & 120000 & 50000 & 10000 & 212000 & 392000 & 151800 &
3036\tabularnewline
JY0002 & 郭秋阳 & 210000 & 50500 & 10300 & 210500 & 481300 & 196310 &
9816\tabularnewline
JY0003 & 林文华 & 80000 & 51000 & 10600 & 80000 & 221600 & 79220 &
0\tabularnewline
JY0004 & 蔡玉云 & 300000 & 30000 & 10900 & 150000 & 490900 & 215180 &
10759\tabularnewline
JY0005 & 陈静雯 & 120000 & 52000 & 12000 & 300000 & 484000 & 187600 &
9380\tabularnewline
JY0006 & 林健华 & 70000 & 52500 & 11500 & 215000 & 349000 & 128550 &
2571\tabularnewline
JY0007 & 刘名昌 & 170000 & 25000 & 8000 & 20000 & 223000 & 97100 &
1942\tabularnewline
JY0008 & 吴丽贞 & 180000 & 53500 & 11100 & 221000 & 465600 & 185970 &
9298\tabularnewline
JY0009 & 林雅琳 & 200000 & 54000 & 10900 & 120000 & 384900 & 155580 &
3112\tabularnewline
JY0010 & 王光辉 & 500000 & 55000 & 12000 & 227000 & 794000 & 348700 &
41844\tabularnewline
NA & 合计 & 1950000 & 473500 & 107300 & 1755500 & 4286300 & 1746010 &
91758\tabularnewline
\bottomrule
\end{longtable}

\subsection{业绩统计季报表}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{thisquarter <-}\StringTok{ "Q1"}
\NormalTok{df.season <-}\StringTok{ }\NormalTok{df }\OperatorTok{%>%}\StringTok{ }\KeywordTok{mutate}\NormalTok{(季度 =}\StringTok{ }\KeywordTok{quarters}\NormalTok{(销售月份))}

\CommentTok{#== 本季度销售情况}
\NormalTok{df.season.detail <-}\StringTok{ }\NormalTok{df.season }\OperatorTok{%>%}\StringTok{ }\NormalTok{dplyr}\OperatorTok{::}\KeywordTok{filter}\NormalTok{(季度 }\OperatorTok{==}\StringTok{ }\NormalTok{thisquarter) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{group_by}\NormalTok{(员工编号, 姓名, 商品种类) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{summarise}\NormalTok{(销售金额 =}\StringTok{ }\KeywordTok{sum}\NormalTok{(销售金额)) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{ungroup}\NormalTok{() }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{spread}\NormalTok{(}\DataTypeTok{key =} \StringTok{"商品种类"}\NormalTok{, }\DataTypeTok{value =} \StringTok{"销售金额"}\NormalTok{) }

\CommentTok{#== 季度汇总表}
\NormalTok{transmute_guize_all <-}\StringTok{ }\ControlFlowTok{function}\NormalTok{(df_, df.guize_, }\DataTypeTok{df.guize.type_ =} \DecValTok{1}\NormalTok{, }\DataTypeTok{df.guize.valueCol_ =} \DecValTok{2}\NormalTok{) \{}
\NormalTok{  df.cols <-}\StringTok{ }\NormalTok{df_[, df.guize_[[df.guize.type_]]]}
\NormalTok{  guize.value <-}\StringTok{ }\NormalTok{df.guize_[[df.guize.valueCol_]]}

\NormalTok{  df.cols.mat <-}\StringTok{ }\NormalTok{df.cols }\OperatorTok{%>%}\StringTok{ }\KeywordTok{as.matrix}\NormalTok{() }
\NormalTok{  rst <-}\StringTok{ }\KeywordTok{sapply}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\KeywordTok{nrow}\NormalTok{(df.cols.mat), }\ControlFlowTok{function}\NormalTok{(w) \{}
\NormalTok{    df.cols.mat[w,] }\OperatorTok{*}\StringTok{ }\NormalTok{guize.value}
\NormalTok{  \})}
\NormalTok{  rst <-}\StringTok{ }\KeywordTok{rowSums}\NormalTok{(}\KeywordTok{t}\NormalTok{(rst))}
  \KeywordTok{return}\NormalTok{(rst)}
\NormalTok{\}}

\NormalTok{df.season.sum <-}\StringTok{ }\NormalTok{df.season.detail }\OperatorTok{%>%}\StringTok{ }
\StringTok{  }\KeywordTok{mutate}\NormalTok{(销售金额 =}\StringTok{ }\KeywordTok{rowSums}\NormalTok{(}\KeywordTok{select}\NormalTok{(., }\KeywordTok{c}\NormalTok{(}\DecValTok{3}\OperatorTok{:}\DecValTok{6}\NormalTok{)))) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{mutate}\NormalTok{(业绩金额 =}\StringTok{ }\KeywordTok{transmute_guize_all}\NormalTok{(., yeji.guize)) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{mutate}\NormalTok{(排名 =}\StringTok{ }\KeywordTok{rank}\NormalTok{(}\OperatorTok{-}\NormalTok{.}\OperatorTok{$}\NormalTok{业绩金额, }\DataTypeTok{ties.method =} \StringTok{"min"}\NormalTok{)) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{arrange}\NormalTok{(}\OperatorTok{-}\NormalTok{业绩金额)}
\NormalTok{knitr}\OperatorTok{::}\KeywordTok{kable}\NormalTok{(df.season.sum, }\DataTypeTok{caption =} \KeywordTok{paste0}\NormalTok{(thisquarter, }\StringTok{"季度汇总表"}\NormalTok{))}
\end{Highlighting}
\end{Shaded}

\begin{longtable}[]{@{}llccccccc@{}}
\caption{Q1季度汇总表}\tabularnewline
\toprule
员工编号 & 姓名 & 财产险 & 旅游平安险 & 汽车强制险 & 意外险 & 销售金额 &
业绩金额 & 排名\tabularnewline
\midrule
\endfirsthead
\toprule
员工编号 & 姓名 & 财产险 & 旅游平安险 & 汽车强制险 & 意外险 & 销售金额 &
业绩金额 & 排名\tabularnewline
\midrule
\endhead
JY0010 & 王光辉 & 1300400 & 172600 & 39400 & 674400 & 2186800 & 945100 &
1\tabularnewline
JY0004 & 蔡玉云 & 900400 & 95600 & 31200 & 350400 & 1377600 & 606160 &
2\tabularnewline
JY0002 & 郭秋阳 & 630400 & 151900 & 32400 & 641900 & 1456600 & 593630 &
3\tabularnewline
JY0008 & 吴丽贞 & 540400 & 160900 & 35200 & 663400 & 1399900 & 558690 &
4\tabularnewline
JY0009 & 林雅琳 & 700400 & 156600 & 47600 & 360400 & 1265000 & 519540 &
5\tabularnewline
JY0005 & 陈静雯 & 360400 & 156400 & 35400 & 750400 & 1302600 & 503080 &
6\tabularnewline
JY0001 & 张芳城 & 360400 & 160600 & 27000 & 624400 & 1172400 & 451420 &
7\tabularnewline
JY0006 & 林健华 & 310400 & 141600 & 31600 & 645400 & 1129000 & 433840 &
8\tabularnewline
JY0007 & 刘名昌 & 530400 & 84600 & 24400 & 165800 & 805200 & 344860 &
9\tabularnewline
JY0003 & 林文华 & 340400 & 153400 & 29000 & 340400 & 863200 & 327500 &
10\tabularnewline
\bottomrule
\end{longtable}

\subsection{业绩年度统计报表}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{thisyear <-}\StringTok{ "2017"}
\NormalTok{df.year <-}\StringTok{ }\NormalTok{df }\OperatorTok{%>%}\StringTok{ }\KeywordTok{mutate}\NormalTok{(年份 =}\StringTok{ }\KeywordTok{year}\NormalTok{(销售月份))}

\CommentTok{#== 本年度销售情况}
\NormalTok{df.year.detail <-}\StringTok{ }\NormalTok{df.year }\OperatorTok{%>%}\StringTok{ }\NormalTok{dplyr}\OperatorTok{::}\KeywordTok{filter}\NormalTok{(年份 }\OperatorTok{==}\StringTok{ }\NormalTok{thisyear) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{group_by}\NormalTok{(员工编号, 姓名, 商品种类) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{summarise}\NormalTok{(销售金额 =}\StringTok{ }\KeywordTok{sum}\NormalTok{(销售金额)) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{ungroup}\NormalTok{() }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{spread}\NormalTok{(}\DataTypeTok{key =} \StringTok{"商品种类"}\NormalTok{, }\DataTypeTok{value =} \StringTok{"销售金额"}\NormalTok{) }

\CommentTok{#== 年度汇总表}
\NormalTok{df.year.sum <-}\StringTok{ }\NormalTok{df.year.detail }\OperatorTok{%>%}\StringTok{ }
\StringTok{  }\KeywordTok{mutate}\NormalTok{(销售金额 =}\StringTok{ }\KeywordTok{rowSums}\NormalTok{(}\KeywordTok{select}\NormalTok{(., }\KeywordTok{c}\NormalTok{(}\DecValTok{3}\OperatorTok{:}\DecValTok{6}\NormalTok{)))) }\OperatorTok{%>%}\StringTok{ }
\StringTok{  }\KeywordTok{mutate}\NormalTok{(业绩金额 =}\StringTok{ }\KeywordTok{transmute_guize_all}\NormalTok{(df.year.detail, }\DataTypeTok{df.guize_ =}\NormalTok{ yeji.guize)) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{mutate}\NormalTok{(排名 =}\StringTok{ }\KeywordTok{rank}\NormalTok{(}\OperatorTok{-}\NormalTok{.}\OperatorTok{$}\NormalTok{业绩金额, }\DataTypeTok{ties.method =} \StringTok{"min"}\NormalTok{)) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{arrange}\NormalTok{(}\OperatorTok{-}\NormalTok{业绩金额)}

\NormalTok{df.year.sum.tmp <-}\StringTok{ }\KeywordTok{colSums}\NormalTok{(df.year.sum[}\DecValTok{3}\OperatorTok{:}\DecValTok{8}\NormalTok{])}
\NormalTok{df.year.sum.tmp <-}\StringTok{ }\NormalTok{df.year.sum.tmp }\OperatorTok{%>%}\StringTok{  }\KeywordTok{t}\NormalTok{() }\OperatorTok{%>%}\StringTok{ }\KeywordTok{as.data.frame}\NormalTok{()}
\NormalTok{df.year.sum.tmp[,}\StringTok{"姓名"}\NormalTok{] <-}\StringTok{ "合计"}
\NormalTok{df.year.sum.end <-}\StringTok{ }\NormalTok{df.year.sum }\OperatorTok{%>%}\StringTok{ }\KeywordTok{bind_rows}\NormalTok{(df.year.sum.tmp)}

\NormalTok{knitr}\OperatorTok{::}\KeywordTok{kable}\NormalTok{(df.year.sum.end, }\DataTypeTok{caption =} \KeywordTok{paste0}\NormalTok{(thisyear, }\StringTok{"年业绩汇总表"}\NormalTok{))}
\end{Highlighting}
\end{Shaded}

\begin{longtable}[]{@{}llccccccc@{}}
\caption{2017年业绩汇总表}\tabularnewline
\toprule
员工编号 & 姓名 & 财产险 & 旅游平安险 & 汽车强制险 & 意外险 & 销售金额 &
业绩金额 & 排名\tabularnewline
\midrule
\endfirsthead
\toprule
员工编号 & 姓名 & 财产险 & 旅游平安险 & 汽车强制险 & 意外险 & 销售金额 &
业绩金额 & 排名\tabularnewline
\midrule
\endhead
JY0010 & 王光辉 & 5227200 & 635400 & 154900 & 2678200 & 8695700 &
3779400 & 1\tabularnewline
JY0008 & 吴丽贞 & 2806400 & 611400 & 147400 & 2663400 & 6228600 &
2559180 & 2\tabularnewline
JY0002 & 郭秋阳 & 2705400 & 550400 & 141600 & 2340400 & 5737800 &
2372220 & 3\tabularnewline
JY0004 & 蔡玉云 & 3145400 & 435600 & 128400 & 1635400 & 5344800 &
2296100 & 4\tabularnewline
JY0009 & 林雅琳 & 2346400 & 630800 & 184400 & 1890400 & 5052000 &
2029320 & 5\tabularnewline
JY0005 & 陈静雯 & 1546400 & 576400 & 160400 & 2851800 & 5135000 &
2003640 & 6\tabularnewline
JY0006 & 林健华 & 1166400 & 622100 & 138500 & 2798400 & 4725400 &
1792470 & 7\tabularnewline
JY0001 & 张芳城 & 1366000 & 688400 & 123800 & 2350000 & 4528200 &
1716600 & 8\tabularnewline
JY0007 & 刘名昌 & 2126400 & 453600 & 142700 & 1057200 & 3779900 &
1559980 & 9\tabularnewline
JY0003 & 林文华 & 1145400 & 619400 & 144800 & 1655400 & 3565000 &
1325760 & 10\tabularnewline
NA & 合计 & 23581400 & 5823500 & 1466900 & 21920600 & 52792400 &
21434670 & NA\tabularnewline
\bottomrule
\end{longtable}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{df.year }\OperatorTok{%>%}\StringTok{ }\KeywordTok{group_by}\NormalTok{(员工编号, 姓名, 商品种类) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{summarise}\NormalTok{(销售金额 =}\StringTok{ }\KeywordTok{sum}\NormalTok{(销售金额)) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{arrange}\NormalTok{(姓名, }\KeywordTok{desc}\NormalTok{(商品种类)) }\OperatorTok{%>%}\StringTok{ }
\StringTok{  }\KeywordTok{mutate}\NormalTok{(}\DataTypeTok{label_y =} \KeywordTok{cumsum}\NormalTok{(销售金额)}\OperatorTok{-}\FloatTok{0.5}\OperatorTok{*}\NormalTok{销售金额) }\OperatorTok{%>%}\StringTok{ }
\StringTok{  }\KeywordTok{ggplot}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\KeywordTok{reorder}\NormalTok{(姓名, }\OperatorTok{-}\NormalTok{销售金额), 销售金额, }\DataTypeTok{fill =}\NormalTok{ 商品种类)) }\OperatorTok{+}
\StringTok{  }\KeywordTok{geom_bar}\NormalTok{(}\DataTypeTok{stat =} \StringTok{"identity"}\NormalTok{) }\OperatorTok{+}
\StringTok{  }\KeywordTok{ggtitle}\NormalTok{(}\KeywordTok{paste0}\NormalTok{(thisyear, }\StringTok{"年销售金额统计图"}\NormalTok{)) }\OperatorTok{+}
\StringTok{  }\KeywordTok{geom_text}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\DataTypeTok{y =}\NormalTok{ label_y, }\DataTypeTok{label =} \KeywordTok{paste0}\NormalTok{(销售金额}\OperatorTok{/}\DecValTok{100}\NormalTok{, }\StringTok{"万"}\NormalTok{)), }\DataTypeTok{size =} \DecValTok{3}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\includegraphics{tp391.13-635-chapter7_files/figure-latex/yearsum-1.pdf}

\subsection{员工年度业绩排名}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{df.year.sum }\OperatorTok{%>%}\StringTok{ }\KeywordTok{mutate}\NormalTok{(}\DataTypeTok{text_yeji =} \KeywordTok{paste0}\NormalTok{(}\KeywordTok{round}\NormalTok{(业绩金额}\OperatorTok{/}\DecValTok{10000}\NormalTok{), }\StringTok{"万"}\NormalTok{),}
                       \DataTypeTok{text_yeji_y =}\NormalTok{ 业绩金额}\OperatorTok{/}\DecValTok{2}\NormalTok{) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{ggplot}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\KeywordTok{reorder}\NormalTok{(姓名, }\OperatorTok{-}\NormalTok{业绩金额), 业绩金额)) }\OperatorTok{+}
\StringTok{  }\KeywordTok{geom_bar}\NormalTok{(}\DataTypeTok{stat =} \StringTok{"identity"}\NormalTok{) }\OperatorTok{+}
\StringTok{  }\KeywordTok{geom_text}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\DataTypeTok{label =}\NormalTok{ text_yeji, }\DataTypeTok{y =}\NormalTok{ text_yeji_y), }\DataTypeTok{size =} \DecValTok{3}\NormalTok{, }\DataTypeTok{color =} \StringTok{"white"}\NormalTok{) }\OperatorTok{+}
\StringTok{  }\KeywordTok{geom_text}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\DataTypeTok{label =}\NormalTok{ 排名, }\DataTypeTok{y =}\NormalTok{ 业绩金额), }\DataTypeTok{vjust =} \OperatorTok{-}\FloatTok{0.5}\NormalTok{) }\OperatorTok{+}
\StringTok{  }\KeywordTok{ggtitle}\NormalTok{(}\KeywordTok{paste0}\NormalTok{(thisyear, }\StringTok{"年员工业绩排名统计图"}\NormalTok{)) }\OperatorTok{+}
\StringTok{  }\KeywordTok{xlab}\NormalTok{(}\StringTok{""}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\includegraphics{tp391.13-635-chapter7_files/figure-latex/year-yeji-1.pdf}

\subsection{年终业绩分红计算图表}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{# 计算分红系数}
\NormalTok{fenhong.guize <-}\StringTok{ }\NormalTok{readxl}\OperatorTok{::}\KeywordTok{read_excel}\NormalTok{(}\StringTok{"./data/tp391.13-635-人事办公管理/chapter7.xlsx"}\NormalTok{, }
                                    \DataTypeTok{sheet =} \StringTok{"参数表"}\NormalTok{,}
                                    \DataTypeTok{range =} \StringTok{"H2:J7"}\NormalTok{)}
\NormalTok{fenhong.guize }\OperatorTok{%>%}\StringTok{ }\NormalTok{head}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## # A tibble: 5 x 3
##    等级    范围  数值
##   <chr>   <dbl> <dbl>
## 1 等级0       0 0.000
## 2 等级1 1100000 0.002
## 3 等级2 2000000 0.005
## 4 等级3 2800000 0.010
## 5 等级4 3600000 0.020
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{df.year.sum}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## # A tibble: 10 x 9
##    员工编号   姓名  财产险 旅游平安险 汽车强制险  意外险 销售金额 业绩金额
##       <chr>  <chr>   <dbl>      <dbl>      <dbl>   <dbl>    <dbl>    <dbl>
##  1   JY0010 王光辉 5227200     635400     154900 2678200  8695700  3779400
##  2   JY0008 吴丽贞 2806400     611400     147400 2663400  6228600  2559180
##  3   JY0002 郭秋阳 2705400     550400     141600 2340400  5737800  2372220
##  4   JY0004 蔡玉云 3145400     435600     128400 1635400  5344800  2296100
##  5   JY0009 林雅琳 2346400     630800     184400 1890400  5052000  2029320
##  6   JY0005 陈静雯 1546400     576400     160400 2851800  5135000  2003640
##  7   JY0006 林健华 1166400     622100     138500 2798400  4725400  1792470
##  8   JY0001 张芳城 1366000     688400     123800 2350000  4528200  1716600
##  9   JY0007 刘名昌 2126400     453600     142700 1057200  3779900  1559980
## 10   JY0003 林文华 1145400     619400     144800 1655400  3565000  1325760
## # ... with 1 more variables: 排名 <int>
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{df.year.sum}\OperatorTok{$}\NormalTok{分红系数 <-}\StringTok{ }\KeywordTok{cut}\NormalTok{(df.year.sum}\OperatorTok{$}\NormalTok{业绩金额, }
                        \DataTypeTok{breaks =} \KeywordTok{c}\NormalTok{(fenhong.guize}\OperatorTok{$}\NormalTok{范围, }\OtherTok{Inf}\NormalTok{), }
                        \DataTypeTok{labels =}\NormalTok{ fenhong.guize}\OperatorTok{$}\NormalTok{数值) }\OperatorTok{%>%}\StringTok{ }
\StringTok{  }\KeywordTok{as.character}\NormalTok{() }\OperatorTok{%>%}\StringTok{ }
\StringTok{  }\KeywordTok{as.numeric}\NormalTok{()}

\NormalTok{df.year.sum <-}\StringTok{ }\NormalTok{df.year.sum }\OperatorTok{%>%}\StringTok{ }\KeywordTok{mutate}\NormalTok{(年终业绩奖金 =}\StringTok{ }\KeywordTok{round}\NormalTok{(业绩金额 }\OperatorTok{*}\StringTok{ }\NormalTok{分红系数))}

\CommentTok{# 读入考核奖金}
\NormalTok{kaohe.jiangjin <-}\StringTok{ }\NormalTok{readxl}\OperatorTok{::}\KeywordTok{read_excel}\NormalTok{(}\StringTok{"./data/tp391.13-635-人事办公管理/chapter7.xlsx"}\NormalTok{, }
                                    \DataTypeTok{sheet =} \StringTok{"分红表"}\NormalTok{)}
\NormalTok{df.year.sum <-}\StringTok{ }\NormalTok{df.year.sum }\OperatorTok{%>%}\StringTok{ }\KeywordTok{left_join}\NormalTok{(kaohe.jiangjin, }\DataTypeTok{by =} \KeywordTok{c}\NormalTok{(}\StringTok{"员工编号"}\NormalTok{, }\StringTok{"姓名"}\NormalTok{))}

\CommentTok{# 计算排名奖金}
\NormalTok{rank.guize <-}\StringTok{ }\NormalTok{readxl}\OperatorTok{::}\KeywordTok{read_excel}\NormalTok{(}\StringTok{"./data/tp391.13-635-人事办公管理/chapter7.xlsx"}\NormalTok{, }
                                 \DataTypeTok{sheet =} \StringTok{"参数表"}\NormalTok{,}
                                 \DataTypeTok{range =} \StringTok{"L2:M7"}\NormalTok{)}
\NormalTok{rank.guize <-}\StringTok{ }\NormalTok{rank.guize }\OperatorTok{%>%}\StringTok{ }\KeywordTok{column_to_rownames}\NormalTok{(}\StringTok{"排名"}\NormalTok{)}
\NormalTok{all.rank1 <-}\StringTok{ }\NormalTok{rank.guize[}\DecValTok{1}\NormalTok{,][[}\DecValTok{1}\NormalTok{]]}
\NormalTok{all.rank2 <-}\StringTok{ }\NormalTok{rank.guize[}\DecValTok{2}\NormalTok{,][[}\DecValTok{1}\NormalTok{]]}
\NormalTok{all.rank3 <-}\StringTok{ }\NormalTok{rank.guize[}\DecValTok{3}\NormalTok{,][[}\DecValTok{1}\NormalTok{]]}
\NormalTok{single.rank1 <-}\StringTok{ }\NormalTok{rank.guize[}\DecValTok{4}\NormalTok{,][[}\DecValTok{1}\NormalTok{]]}
\NormalTok{single.rank2 <-}\StringTok{ }\NormalTok{rank.guize[}\DecValTok{5}\NormalTok{,][[}\DecValTok{1}\NormalTok{]]}

\CommentTok{# 算出单项冠亚军奖金}
\NormalTok{single.rank.jiangjin <-}\StringTok{ }\NormalTok{df.year.sum }\OperatorTok{%>%}\StringTok{ }\KeywordTok{select}\NormalTok{(}\DecValTok{3}\OperatorTok{:}\DecValTok{6}\NormalTok{) }\OperatorTok{%>%}\StringTok{ }\KeywordTok{sapply}\NormalTok{(}\ControlFlowTok{function}\NormalTok{(w) \{}
  \KeywordTok{rank}\NormalTok{(}\OperatorTok{-}\NormalTok{w)}
\NormalTok{\}) }\OperatorTok{%>%}\StringTok{ }\KeywordTok{as.matrix}\NormalTok{() }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{sapply}\NormalTok{(}\ControlFlowTok{function}\NormalTok{(w) \{}
    \ControlFlowTok{if}\NormalTok{(w }\OperatorTok{==}\StringTok{ }\DecValTok{1}\NormalTok{) \{}
\NormalTok{    single.rank1}
\NormalTok{  \} }\ControlFlowTok{else} \ControlFlowTok{if}\NormalTok{ (w }\OperatorTok{==}\StringTok{ }\DecValTok{2}\NormalTok{) \{}
\NormalTok{    single.rank2}
\NormalTok{  \} }\ControlFlowTok{else}\NormalTok{ \{}
    \DecValTok{0}
\NormalTok{  \}}
\NormalTok{\}) }\OperatorTok{%>%}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\DataTypeTok{ncol =} \DecValTok{4}\NormalTok{)}

\CommentTok{# 合并总排名前三名}
\NormalTok{rank.jiangjin <-}\StringTok{ }\KeywordTok{sapply}\NormalTok{(df.year.sum}\OperatorTok{$}\NormalTok{排名, }\ControlFlowTok{function}\NormalTok{(w) \{}
  \ControlFlowTok{if}\NormalTok{(w }\OperatorTok{==}\StringTok{ }\DecValTok{1}\NormalTok{) \{}
\NormalTok{    all.rank1}
\NormalTok{  \}}\ControlFlowTok{else} \ControlFlowTok{if}\NormalTok{(w }\OperatorTok{==}\StringTok{ }\DecValTok{2}\NormalTok{) \{}
\NormalTok{    all.rank2}
\NormalTok{  \}}\ControlFlowTok{else} \ControlFlowTok{if}\NormalTok{(w }\OperatorTok{==}\StringTok{ }\DecValTok{3}\NormalTok{) \{}
\NormalTok{    all.rank3}
\NormalTok{  \}}\ControlFlowTok{else}\NormalTok{ \{}
    \DecValTok{0}
\NormalTok{  \}}
\NormalTok{\}) }\OperatorTok{%>%}\StringTok{ }\KeywordTok{cbind}\NormalTok{(single.rank.jiangjin)}

\CommentTok{# 算出总排名奖金}
\NormalTok{df.year.sum}\OperatorTok{$}\NormalTok{排名奖金 <-}\StringTok{ }\NormalTok{rank.jiangjin }\OperatorTok{%>%}\StringTok{ }\KeywordTok{rowSums}\NormalTok{()}

\CommentTok{# 算出合计奖金}
\NormalTok{df.year.sum}\OperatorTok{$}\NormalTok{奖金合计 <-}\StringTok{ }\NormalTok{df.year.sum }\OperatorTok{%>%}\StringTok{ }
\StringTok{  }\KeywordTok{select}\NormalTok{(}\StringTok{"年终业绩奖金"}\NormalTok{, }\StringTok{"考绩奖金"}\NormalTok{, }\StringTok{"排名奖金"}\NormalTok{) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{rowSums}\NormalTok{()}

\NormalTok{df.year.jiangjin <-}\StringTok{ }\NormalTok{df.year.sum }\OperatorTok{%>%}\StringTok{ }\KeywordTok{select}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{2}\NormalTok{, }\StringTok{"年终业绩奖金"}\NormalTok{, }\StringTok{"考绩奖金"}\NormalTok{, }\StringTok{"排名奖金"}\NormalTok{, }\StringTok{"奖金合计"}\NormalTok{) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{arrange}\NormalTok{(}\OperatorTok{-}\NormalTok{奖金合计)}

\NormalTok{df.year.jiangjin.sum <-}\StringTok{ }\KeywordTok{colSums}\NormalTok{(df.year.jiangjin[}\DecValTok{3}\OperatorTok{:}\DecValTok{6}\NormalTok{])}
\NormalTok{df.year.jiangjin.sum <-}\StringTok{ }\NormalTok{df.year.jiangjin.sum }\OperatorTok{%>%}\StringTok{  }\KeywordTok{t}\NormalTok{() }\OperatorTok{%>%}\StringTok{ }\KeywordTok{as.data.frame}\NormalTok{()}
\NormalTok{df.year.jiangjin.sum[,}\StringTok{"姓名"}\NormalTok{] <-}\StringTok{ "合计"}

\CommentTok{# 输出奖金表格}
\NormalTok{df.year.jiangjin }\OperatorTok{%>%}\StringTok{ }\KeywordTok{bind_rows}\NormalTok{(df.year.jiangjin.sum) }\OperatorTok{%>%}\StringTok{ }\NormalTok{knitr}\OperatorTok{::}\KeywordTok{kable}\NormalTok{()}
\end{Highlighting}
\end{Shaded}

\begin{longtable}[]{@{}llcccc@{}}
\toprule
员工编号 & 姓名 & 年终业绩奖金 & 考绩奖金 & 排名奖金 &
奖金合计\tabularnewline
\midrule
\endhead
JY0010 & 王光辉 & 75588 & 10000 & 121600 & 207188\tabularnewline
JY0005 & 陈静雯 & 10018 & 5000 & 53600 & 68618\tabularnewline
JY0008 & 吴丽贞 & 12796 & 10000 & 38000 & 60796\tabularnewline
JY0009 & 林雅琳 & 10147 & 5000 & 36800 & 51947\tabularnewline
JY0001 & 张芳城 & 3433 & 5000 & 36800 & 45233\tabularnewline
JY0004 & 蔡玉云 & 11480 & 10000 & 16800 & 38280\tabularnewline
JY0002 & 郭秋阳 & 11861 & 1000 & 16800 & 29661\tabularnewline
JY0006 & 林健华 & 3585 & 1000 & 16800 & 21385\tabularnewline
JY0007 & 刘名昌 & 3120 & 5000 & 0 & 8120\tabularnewline
JY0003 & 林文华 & 2652 & 5000 & 0 & 7652\tabularnewline
NA & 合计 & 144680 & 57000 & 337200 & 538880\tabularnewline
\bottomrule
\end{longtable}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{jiangjin.label.x =}\StringTok{ }\DecValTok{1}\OperatorTok{:}\KeywordTok{length}\NormalTok{(df.year.jiangjin}\OperatorTok{$}\NormalTok{姓名)}
\NormalTok{jiangjin.label.y <-}\StringTok{ }\NormalTok{df.year.jiangjin}\OperatorTok{$}\NormalTok{奖金合计 }\OperatorTok{-}\StringTok{ }\DecValTok{1000}
\NormalTok{jiangjin.labels <-}\StringTok{ }\KeywordTok{paste0}\NormalTok{(}\KeywordTok{round}\NormalTok{(df.year.jiangjin}\OperatorTok{$}\NormalTok{奖金合计}\OperatorTok{/}\DecValTok{10000}\NormalTok{, }\DecValTok{2}\NormalTok{), }\StringTok{"万"}\NormalTok{)}
\NormalTok{df.year.jiangjin }\OperatorTok{%>%}\StringTok{ }\KeywordTok{select}\NormalTok{(}\DecValTok{2}\OperatorTok{:}\DecValTok{5}\NormalTok{) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{gather}\NormalTok{(}\DataTypeTok{key =} \StringTok{"奖金类型"}\NormalTok{, }\DataTypeTok{value =} \StringTok{"金额"}\NormalTok{, }\DecValTok{2}\OperatorTok{:}\DecValTok{4}\NormalTok{) }\OperatorTok{%>%}
\StringTok{  }\KeywordTok{ggplot}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\KeywordTok{reorder}\NormalTok{(姓名, }\OperatorTok{-}\NormalTok{金额), 金额, }\DataTypeTok{fill =}\NormalTok{ 奖金类型)) }\OperatorTok{+}
\StringTok{  }\KeywordTok{geom_bar}\NormalTok{(}\DataTypeTok{stat =} \StringTok{"identity"}\NormalTok{) }\OperatorTok{+}
\StringTok{  }\NormalTok{ggplot2}\OperatorTok{::}\KeywordTok{annotate}\NormalTok{(}\DataTypeTok{geom =} \StringTok{"text"}\NormalTok{, }
                    \DataTypeTok{x =}\NormalTok{ jiangjin.label.x, }
                    \DataTypeTok{y =}\NormalTok{ jiangjin.label.y, }
                    \DataTypeTok{label =}\NormalTok{ jiangjin.labels,}
                    \DataTypeTok{size =} \DecValTok{4}\NormalTok{) }\OperatorTok{+}
\StringTok{  }\KeywordTok{ggtitle}\NormalTok{(}\KeywordTok{paste0}\NormalTok{(thisyear, }\StringTok{"年奖金统计图"}\NormalTok{)) }\OperatorTok{+}
\StringTok{  }\KeywordTok{xlab}\NormalTok{(}\StringTok{""}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\includegraphics{tp391.13-635-chapter7_files/figure-latex/fenhong-1.pdf}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{jiangjin.label.x}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
##  [1]  1  2  3  4  5  6  7  8  9 10
\end{verbatim}

\subsection{员工年度业绩分析}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{yg.names <-}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"王光辉"}\NormalTok{, }\StringTok{"林文华"}\NormalTok{, }\StringTok{"吴丽贞"}\NormalTok{)}
\KeywordTok{windowsFonts}\NormalTok{(}\DataTypeTok{yahei =} \StringTok{"MS YAHEI"}\NormalTok{)}
\NormalTok{df.year.detail.rescale <-}\StringTok{ }\NormalTok{df.year.detail }\OperatorTok{%>%}\StringTok{ }
\StringTok{  }\KeywordTok{mutate_if}\NormalTok{(}\DataTypeTok{.predicate =}\NormalTok{ is.numeric, scales}\OperatorTok{::}\NormalTok{rescale)}
\CommentTok{#df.year.detail.rescale}
\NormalTok{df.year.detail.rescale }\OperatorTok{%>%}\StringTok{ }\KeywordTok{select}\NormalTok{(}\OperatorTok{-}\DecValTok{1}\NormalTok{) }\OperatorTok{%>%}
\StringTok{  }\NormalTok{dplyr}\OperatorTok{::}\KeywordTok{filter}\NormalTok{(姓名 }\OperatorTok{%in%}\StringTok{ }\NormalTok{yg.names) }\OperatorTok{%>%}
\StringTok{  }\NormalTok{ggradar}\OperatorTok{::}\KeywordTok{ggradar}\NormalTok{(}\DataTypeTok{plot.data =}\NormalTok{ ., }\DataTypeTok{font.radar =} \StringTok{"yahei"}\NormalTok{,}
                   \DataTypeTok{group.point.size =} \DecValTok{3}\NormalTok{,}
                   \DataTypeTok{axis.label.size =} \DecValTok{3}\NormalTok{,}
                   \DataTypeTok{legend.text.size =} \DecValTok{12}\NormalTok{) }\OperatorTok{+}
\StringTok{  }\KeywordTok{ggtitle}\NormalTok{(}\StringTok{"员工不同保险销售对比"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\includegraphics{tp391.13-635-chapter7_files/figure-latex/yuangong-yeji-1.pdf}

\end{document}
